package MypageController.MyMain;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import common.PagingManager;

import CommunityController.BCBoardDAO;
import CommunityController.FreeBoardDAO;
import MypageController.MyComment.MyCommentBean;
import MypageController.MyKategore.MyKategoreBean;
import MypageController.MyWrite.MyWriteBean;
import PhotoController.PhotoYoungDAO;

/**
 * Servlet implementation class MyMainServ
 */
public class MyMainServ extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MyMainServ() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("UTF-8");
 		response.setCharacterEncoding("UTF-8");
 		response.setContentType("text/html; charset=UTF-8");
 		RequestDispatcher view = null;
 		
 		
 		MyMainDAO mymaindao = new MyMainDAO();
 		MyMainBean mymainbean = new MyMainBean();
 		MyWriteBean[] mywritebean = null;
 		MyCommentBean[] mycommentbean = null;
 		MyCommentBean[] entriesmycommentbean = null;
 		MyKategoreBean[] kategorilist = null;
 		String action=request.getParameter("action");
 		String id=null;
 		
 		if(request.getParameter("id") != null){
 			id=request.getParameter("id");
 		}
 		
 		int mypageid = -1;
 		boolean comparison;
 		String you = "no";
 		String url;
/************************************************************************************************************/
 		if(action.equals("MyList")){
 			
System.out.println("--------------블로그 유/무 판별 부분----------------");
 			
 			int idnumber = mymaindao.idGet(id);

			mypageid = mymaindao.existence(idnumber, id);
 			int level = mymaindao.level(id);

System.out.println("접속자 ID 번호: " + idnumber + " || 접속자 ID 이름 : " + id + " || 블로그 번호 : " + mypageid);

 			if(mypageid != -1){
System.out.println("-------------------블로그가 기존에 있음----------------"); 				
 				if(level == 2){
System.out.println("--------------젊은이 메인으로 마이 페이지 뿌림----------------"); 						
					
					Integer[] entriesid = mymaindao.entriesIdGet(mypageid);
					mymainbean = mymaindao.myPageDataGet(mypageid);
					if(entriesid.length == 0){
						
						kategorilist = mymaindao.kategoriesGet(mypageid);
						for(int i = 0; i<kategorilist.length; i++){
							kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
						}
						
	 					String pagename = "/Mypage/Mp_EntNot";
	 					request.setAttribute("page", pagename);
	 					
						request.setAttribute("id", id);
						request.setAttribute("kategorilist", kategorilist);
						request.setAttribute("mypage", "mypage");
						request.setAttribute("mypagedata", mymainbean);
						request.setAttribute("level", level);
						request.setAttribute("mypageid", mypageid);
	 					view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
	 					view.forward(request,response); 
	 					
					}else{

						int number = 0;
						if(request.getParameter("number") != null){
							number=Integer.parseInt(request.getParameter("number"));
						} 					
	
						you = mymaindao.youNickGet(idnumber);
						kategorilist = mymaindao.kategoriesGet(mypageid);
						for(int i = 0; i<kategorilist.length; i++){
							kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
						}
						String[] kategdate = mymaindao.kategoriesDateGet(mypageid);
						
				
						for(int i = 0; i<entriesid.length;i++){		
							mymaindao.commentCountSet(entriesid[i]);
							mymaindao.entriesNumberSet(entriesid[i], i);
						}
						mywritebean = mymaindao.latestEntriesGet(mypageid, number);
						int entriesnumber = entriesid[0];
						if(request.getParameter("entriesid") != null){
							entriesnumber=Integer.parseInt(request.getParameter("entriesid"));
				 		}
						entriesmycommentbean = mymaindao.commentGet(mypageid, entriesnumber);
						mycommentbean = mymaindao.latestComment(mypageid);
						
						for(int i=0;i<mycommentbean.length;i++){	
							int entriesnum = mymaindao.entriesNumberGet(mycommentbean[i].getEntries_Id());
							mycommentbean[i].setEntries_Number(entriesnum);
						}
						mymainbean = mymaindao.myPageDataGet(mypageid);
									
System.out.println("마이 페이지 제작자 : " + id + " || 중 고령층 공유자 : " + you +" || 접속자 레벨 : " + level);
									
	 					String pagename = "/Mypage/Mp_Read";
	 					request.setAttribute("page", pagename);
						request.setAttribute("number", number);
						request.setAttribute("numbermax", entriesid.length - 1);
						request.setAttribute("id", id);
						request.setAttribute("mypagedata", mymainbean);
						request.setAttribute("mypage", "mypage");
						request.setAttribute("level", level);
						request.setAttribute("mypageid", mypageid);
						request.setAttribute("entries", mywritebean);
						request.setAttribute("kategorilist", kategorilist);
						request.setAttribute("kategdate", kategdate);
						request.setAttribute("latestcomment", mycommentbean);
						request.setAttribute("commentlist", entriesmycommentbean);
	 					view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
	 					view.forward(request,response); 
					}
 				}else if(level == 1){
System.out.println("--------------중 고령층 메인으로 마이 페이지 뿌림----------------"); 	 					 					
					
					mypageid = mymaindao.recognition(id);
 
					if(mypageid == 0){
						
System.out.println("--------------블로그에 공유자로 입력은 되었으나 아직 승인을 안한 상테----------------"); 
						you = mymaindao.youNickGet2(id);
						
						String pagename = "/Mypage/Mp_Notify";
						
						Integer[] membersid = mymaindao.membersIdGet(id);
						String[] membersnicklist = mymaindao.membersNickGet(membersid);

						request.setAttribute("page", pagename);	
						request.setAttribute("id", id);
						request.setAttribute("you", membersnicklist);
						request.setAttribute("division", "recognition");
						view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
						view.forward(request,response);

					}else{
						
						Integer[] entriesid = mymaindao.entriesIdGet(mypageid);
						mymainbean = mymaindao.myPageDataGet(mypageid);
						kategorilist = mymaindao.kategoriesGet(mypageid);
						int count = kategorilist.length;
System.out.println("カテゴリ数 = "+count);
						for(int i = 0; i<kategorilist.length; i++){
							kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
						}

							
						if(entriesid.length == 0){
							System.out.println("글 없다.");
							
		 					String pagename = "/Mypage/Mp_EntNot";
		 					request.setAttribute("page", pagename);
							request.setAttribute("id", id);
							request.setAttribute("mypagedata", mymainbean);
							request.setAttribute("kategorilist", kategorilist);
							request.setAttribute("mypage", "mypage");
							request.setAttribute("level", level);
							request.setAttribute("mypageid", mypageid);
		 					view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
		 					view.forward(request,response); 
		 					
						}else{

							int number = 0;
							if(request.getParameter("number") != null){
								number=Integer.parseInt(request.getParameter("number"));
					 		}
							
	System.out.println("넘어온 숫자 = " + number);

							String[] kategdate = mymaindao.kategoriesDateGet(mypageid);
							
							for(int i = 0; i<entriesid.length;i++){		
								mymaindao.commentCountSet(entriesid[i]);
								mymaindao.entriesNumberSet(entriesid[i], i);
							}
							mywritebean = mymaindao.latestEntriesGet(mypageid, number);
							int entriesnumber = entriesid[0];
							if(request.getParameter("entriesid") != null){
								entriesnumber=Integer.parseInt(request.getParameter("entriesid"));
					 		}
							entriesmycommentbean = mymaindao.commentGet(mypageid, entriesnumber);
							mycommentbean = mymaindao.latestComment(mypageid);
							
							for(int i=0;i<mycommentbean.length;i++){	
								int entriesnum = mymaindao.entriesNumberGet(mycommentbean[i].getEntries_Id());
								mycommentbean[i].setEntries_Number(entriesnum);
							}
							mymainbean = mymaindao.myPageDataGet(mypageid);
	
	System.out.println("엔트리 아이디 = " + entriesnumber);
	System.out.println("블로그 아이디 = " + mypageid);
	System.out.println("마이 페이지 제작자 : " + you + " || 중 고령층 공유자 : " + id +" || 접속자 레벨 : " + level);						
							
							String pagename = "/Mypage/Mp_Read";
							request.setAttribute("page", pagename);
							request.setAttribute("number", number);
							request.setAttribute("numbermax", entriesid.length - 1);
							request.setAttribute("id", id);
							request.setAttribute("mypagedata", mymainbean);
							request.setAttribute("mypage", "mypage");
							request.setAttribute("level", level);
							request.setAttribute("mypageid", mypageid);					
							request.setAttribute("entries", mywritebean);
							request.setAttribute("kategorilist", kategorilist);
							request.setAttribute("kategdate", kategdate);
							request.setAttribute("latestcomment", mycommentbean);
							request.setAttribute("commentlist", entriesmycommentbean);
							view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
							view.forward(request,response); 
						}	
					}	
 				}else{
System.out.println("나이 구분 오류");	
 				}	
 			}else{
System.out.println("--------------블로그가 없음----------------"); 	
 				if(level == 2){
 					
 					int check = mymaindao.productionCheck(mymaindao.idGet(id));
 					
 					if(check == 5){
 						String nick = mymaindao.nick(mymaindao.oldIdGet(mymaindao.idGet(id)));
 						
 						String pagename = "/Mypage/Mp_Main";
 	 					request.setAttribute("page", pagename);
 	 					request.setAttribute("id", id);
 	 					request.setAttribute("you", nick);
 	 					view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
 	 					view.forward(request,response); 
 					}else{
 						String pagename = "/Mypage/Mp_Notify";
 						request.setAttribute("page", pagename);	
 						request.setAttribute("id", id);
 						request.setAttribute("division", "no");
 						view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
 						view.forward(request,response);
 					}
 					
 				}else if(level == 1){
 					
 					System.out.println("노인은 블로그 작성 불가");

					String pagename = "/Mypage/Mp_Notify";
					request.setAttribute("page", pagename);	
					request.setAttribute("id", id);
					request.setAttribute("division", "error");
					view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
					view.forward(request,response);
 					
 				}else{
System.out.println("오류");
 				}	
 			}
/************************************************************************************************************/
 		}else if(action.equals("back")){
 			System.out.println("뒤로");
			
			PhotoYoungDAO photoYoungDAO=new PhotoYoungDAO();
			BCBoardDAO bCBoardDAO=new BCBoardDAO();
			FreeBoardDAO freeBoardDAO=new FreeBoardDAO();

			ArrayList list=photoYoungDAO.pt_young_list_main();
			ArrayList list2=freeBoardDAO.cm_free_list_main();
			ArrayList list3=bCBoardDAO.cm_bc_list_main();

			request.setAttribute("list",list);
			request.setAttribute("list2",list2);
			request.setAttribute("list3",list3);
			
			view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
			view.forward(request,response);
/*******************************************************************************************************/ 		
 		}else if(action.equals("backyoung")){
 			PrintWriter out =response.getWriter();
 			out.println( "<script>" );
			out.println( "location.href=\"/KOMORIUTA/MYoungAction.do?\";" );
			out.println( "</script>" );
 		}else if(action.equals("refusal")){
 		
 			you = request.getParameter("you");			
 			mymaindao.shareDelet(mymaindao.idGet(you));
 			
 			view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
			view.forward(request,response);
/****************************************************************************************************/ 		
 		}else if(action.equals("definite")){
 			int level = mymaindao.level(id);
 			you = request.getParameter("you");
 			mypageid = mymaindao.recognition(you);		
 			mymaindao.memberMypageIdSet(id, mypageid);
 			Integer[] entriesid = mymaindao.entriesIdGet(mypageid);
 			
 			kategorilist = mymaindao.kategoriesGet(mypageid);
			for(int i = 0; i<kategorilist.length; i++){
				kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
			}
 			
			if(entriesid.length == 0){
				mymainbean = mymaindao.myPageDataGet(mypageid);
				
				String pagename = "/Mypage/Mp_EntNot";
				request.setAttribute("page", pagename);
				request.setAttribute("id", id);
				request.setAttribute("kategorilist", kategorilist);
				request.setAttribute("mypagedata", mymainbean);
				request.setAttribute("mypage", "mypage");
				request.setAttribute("level", level);
				request.setAttribute("mypageid", mypageid);
				view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
				view.forward(request,response); 
					
			}else{
 			
				int number = 0;
				if(request.getParameter("number") != null){
					number=Integer.parseInt(request.getParameter("number"));
		 		}
				
	System.out.println("넘어온 숫자 = " + number);
				
				String[] kategdate = mymaindao.kategoriesDateGet(mypageid);
				
				for(int i = 0; i<entriesid.length;i++){		
					mymaindao.commentCountSet(entriesid[i]);
					mymaindao.entriesNumberSet(entriesid[i], i);
				}
				mywritebean = mymaindao.latestEntriesGet(mypageid, number);
				int entriesnumber = entriesid[0];
				if(request.getParameter("entriesid") != null){
					entriesnumber=Integer.parseInt(request.getParameter("entriesid"));
		 		}
				entriesmycommentbean = mymaindao.commentGet(mypageid, entriesnumber);
				mycommentbean = mymaindao.latestComment(mypageid);
				
				for(int i=0;i<mycommentbean.length;i++){	
					int entriesnum = mymaindao.entriesNumberGet(mycommentbean[i].getEntries_Id());
					mycommentbean[i].setEntries_Number(entriesnum);
				}						
				mymainbean = mymaindao.myPageDataGet(mypageid);
	System.out.println("엔트리 아이디 = " + entriesnumber);
	System.out.println("마이 페이지 제작자 : " + you + " || 중 고령층 공유자 : " + id +" || 접속자 레벨 : " + level);						
				
				String pagename = "/Mypage/Mp_Read";
				request.setAttribute("page", pagename);
				request.setAttribute("number", number);
				request.setAttribute("numbermax", entriesid.length - 1);
				request.setAttribute("id", id);
				request.setAttribute("mypagedata", mymainbean);
				request.setAttribute("mypage", "mypage");
				request.setAttribute("level", level);
				request.setAttribute("mypageid", mypageid);					
				request.setAttribute("entries", mywritebean);
				request.setAttribute("kategorilist", kategorilist);
				request.setAttribute("kategdate", kategdate);
				request.setAttribute("latestcomment", mycommentbean);
				request.setAttribute("commentlist", entriesmycommentbean);
				view=request.getRequestDispatcher("/Main/OldMain/Om_Main.jsp");
				view.forward(request,response); 
			}
 		}else if(action.equals("MyWrite")){
System.out.println("------------- 블로그 작성 부분 --------------------------");

 			mymainbean.setMembers_Id(mymaindao.idGet(id));
 			mymainbean.setBlog_Tilte(request.getParameter("title"));
 			mymainbean.setBlog_Share(request.getParameter("nick"));
 			mymainbean.setBlog_Intro(request.getParameter("textarea"));
 				
 			mypageid = mymaindao.write(mymainbean);
 			mymaindao.memberMypageIdSet(id, mypageid);
 			String value[] = request.getParameterValues("menu");
 			if(value != null){
 				mymaindao.kategorie(mypageid, value);
 			}

 			
			kategorilist = mymaindao.kategoriesGet(mypageid);
			for(int i = 0; i<kategorilist.length; i++){
				kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
			}
			Integer[] entriesid = mymaindao.entriesIdGet(mypageid);
			for(int i = 0; i<entriesid.length;i++){		
				mymaindao.commentCountSet(entriesid[i]);					
			}
			mymainbean = mymaindao.myPageDataGet(mypageid);
System.out.println("마이 페이지 제작자 : " + id + " || 중 고령층 공유자 : " + you);
			
			String pagename = "/Mypage/Mp_EntNot";
			request.setAttribute("page", pagename);
			request.setAttribute("id", id);
			request.setAttribute("mypage", "mypage");
			request.setAttribute("mypagedata", mymainbean);
			request.setAttribute("level", 2);
			request.setAttribute("mypageid", mypageid);
			request.setAttribute("entries", mywritebean);
			request.setAttribute("kategorilist", kategorilist);
			view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
			view.forward(request,response);
			
/************************************************************************************************************/						
 		}else if(action.equals("manage")){
 		
 			mypageid = Integer.parseInt(request.getParameter("mypageid"));
 			
 			you = mymaindao.youNickGet(mymaindao.idGet(id));
System.out.println("상대방 상태 =" + you + " || 제작자 id = " + mymaindao.idGet(id));
 			int value = 0;
 			if(you == null){
 				value = 1; // 승낙 거절 상태
 			}else{
			
 				if(mymaindao.recognition(you) == 0){
 					value = 2; // 승낙 대기 상태
 				}else{
 					value = 3; //공유자 있는 상태
 				}
 			}
 			int level = mymaindao.level(id);
 			String[] kategdate = mymaindao.kategoriesDateGet(mypageid);
 			kategorilist = mymaindao.kategoriesGet(mypageid);	
			for(int i = 0; i<kategorilist.length; i++){
				kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
			}
			mycommentbean = mymaindao.latestComment(mypageid);
			for(int i=0;i<mycommentbean.length;i++){						
				int entriesnum = mymaindao.entriesNumberGet(mycommentbean[i].getEntries_Id());
				mycommentbean[i].setEntries_Number(entriesnum);
			}
			mymainbean = mymaindao.myPageDataGet(mypageid);
			
			String pagename = "/Mypage/Mp_Manage";
			request.setAttribute("page", pagename);
			request.setAttribute("id", id);
			request.setAttribute("you", you);
			request.setAttribute("level", level);
			request.setAttribute("mypage", "mypage");
			request.setAttribute("mypageid", mypageid);
			request.setAttribute("value", value);
			request.setAttribute("mypagedata", mymainbean);
			request.setAttribute("kategorilist", kategorilist);
			request.setAttribute("kategdate", kategdate);
			request.setAttribute("latestcomment", mycommentbean);
			view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
			view.forward(request,response); 
 		
 		}else if(action.equals("manageset")){
 		
 			mypageid = Integer.parseInt(request.getParameter("mypageid"));	
 			Integer[] entriesid = mymaindao.entriesIdGet(mypageid);
 			int level = mymaindao.level(id);
			kategorilist = mymaindao.kategoriesGet(mypageid);
			for(int i = 0; i<kategorilist.length; i++){
				kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
			}		
 			if(entriesid.length == 0){
 				
				mymainbean = mymaindao.myPageDataGet(mypageid);
				
				String pagename = "/Mypage/Mp_EntNot";
				request.setAttribute("page", pagename);
				request.setAttribute("id", id);
				request.setAttribute("kategorilist", kategorilist);
				request.setAttribute("mypagedata", mymainbean);
				request.setAttribute("mypage", "mypage");
				request.setAttribute("level", level);
				request.setAttribute("mypageid", mypageid);
				view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
				view.forward(request,response); 
 				
 			}else{
 			
	 			String nick = mymaindao.youNickGet(mymaindao.idGet(id));
	 			
	 			if(request.getParameter("nick") != null){
	 				nick = request.getParameter("nick");
	 			}
	 			
	 			String title = request.getParameter("title");
	 			String textarea = request.getParameter("textarea");
	 			mymainbean.setBlog_Share(nick);
	 			mymainbean.setBlog_Tilte(title);
	 			mymainbean.setBlog_Intro(textarea);
	 		
	 			mymaindao.myPageRevision(mypageid, mymainbean);
	 			
	 			
	 			int number = 0;
				if(request.getParameter("number") != null){
					number=Integer.parseInt(request.getParameter("number"));
				} 					
	
				String[] kategdate = mymaindao.kategoriesDateGet(mypageid);
				
				
				for(int i = 0; i<entriesid.length;i++){		
					mymaindao.commentCountSet(entriesid[i]);
					mymaindao.entriesNumberSet(entriesid[i], i);
				}
				mywritebean = mymaindao.latestEntriesGet(mypageid, number);
				int entriesnumber = entriesid[0];
				if(request.getParameter("entriesid") != null){
					entriesnumber=Integer.parseInt(request.getParameter("entriesid"));
		 		}
				entriesmycommentbean = mymaindao.commentGet(mypageid, entriesnumber);
				mycommentbean = mymaindao.latestComment(mypageid);
				
				for(int i=0;i<mycommentbean.length;i++){	
					int entriesnum = mymaindao.entriesNumberGet(mycommentbean[i].getEntries_Id());
					mycommentbean[i].setEntries_Number(entriesnum);
				}
				mymainbean = mymaindao.myPageDataGet(mypageid);			
	System.out.println("마이 페이지 제작자 : " + id + " || 중 고령층 공유자 : " + you +" || 접속자 레벨 : " + level);
							
				String pagename = "/Mypage/Mp_Read";
				request.setAttribute("page", pagename);
				request.setAttribute("number", number);
				request.setAttribute("numbermax", entriesid.length - 1);
				request.setAttribute("id", id);
				request.setAttribute("mypagedata", mymainbean);
				request.setAttribute("mypage", "mypage");
				request.setAttribute("level", level);
				request.setAttribute("mypageid", mypageid);
				request.setAttribute("entries", mywritebean);
				request.setAttribute("kategorilist", kategorilist);
				request.setAttribute("kategdate", kategdate);
				request.setAttribute("latestcomment", mycommentbean);
				request.setAttribute("commentlist", entriesmycommentbean);
				view=request.getRequestDispatcher("/Main/YoungMain/Ym_Main.jsp");
				view.forward(request,response); 
 			
 			}
 			
 		}else if(action.equals("WholeEntries")){
 			
 			mypageid = Integer.parseInt(request.getParameter("mypageid"));
 			
 			int currentPage = 1;
 			if(request.getParameter("currentPage")!=null && !"".equals(request.getParameter("currentPage"))){
				currentPage=Integer.parseInt(request.getParameter("currentPage"));
			}
 			if(currentPage == 0){
 				currentPage = 1;
 			}

 		   	HashMap param=new HashMap();
			param = new HashMap<String, Object>();
			param.clear();
			
			param.put("pageSize", 7);
			param.put("currentPage", currentPage );
			param.put("pageGroupSize", 5 );
			int count = mymaindao.entriesCount(mypageid);
			param.put("totalCount", count);

			PagingManager paging = new common.PagingManager();
			paging.setPageNo(param);
				
 			int level = mymaindao.level(id);
			kategorilist = mymaindao.kategoriesGet(mypageid);
			for(int i = 0; i<kategorilist.length; i++){
				kategorilist[i].setKate_Count(mymaindao.kategorisCountGet(mypageid, kategorilist[i].getKeta_Title()));
			}
			String[] kategdate = mymaindao.kategoriesDateGet(mypageid);
			Integer[] entriesid = mymaindao.entriesIdGet(mypageid);
			
			for(int i = 0; i<entriesid.length;i++){		
				mymaindao.commentCountSet(entriesid[i]);
				mymaindao.entriesNumberSet(entriesid[i], i);
			}
			mywritebean = mymaindao.entriesGet(mypageid, currentPage, 7);
			
			mycommentbean = mymaindao.latestComment(mypageid);
			for(int i=0;i<mycommentbean.length;i++){						
				int entriesnum = mymaindao.entriesNumberGet(mycommentbean[i].getEntries_Id());
				mycommentbean[i].setEntries_Number(entriesnum);
			}
			mymainbean = mymaindao.myPageDataGet(mypageid);
				
			String pagename = "/Mypage/Mp_Bord";
			request.setAttribute("paging", paging.getReturnHtml());
			request.setAttribute("page", pagename);
			request.setAttribute("currentPage", currentPage);
			request.setAttribute("id", id);
			request.setAttribute("mypagedata", mymainbean);
			request.setAttribute("mypage", "mypage");
			request.setAttribute("level", level);
			request.setAttribute("mypageid", mypageid);
			request.setAttribute("entries", mywritebean);
			request.setAttribute("kategorilist", kategorilist);
			request.setAttribute("kategdate", kategdate);
			request.setAttribute("latestcomment", mycommentbean);
			if(level == 1){
				url="/Main/OldMain/Om_Main.jsp";
			}else{
				url="/Main/YoungMain/Ym_Main.jsp";
			}
	
			view=request.getRequestDispatcher(url);
			view.forward(request,response); 
		
 			
 		}else if(action.equals("ajax")){
System.out.println("-------------------아작스 부분--------------------");
System.out.println("입력한 text값 : " + id); 			
			
			comparison = mymaindao.distinction(id);
			String resultString = null;
			int result;

			if(comparison){

				result = 1;
				resultString = "<response><result>"+result+"</result></response>";
			    PrintWriter out = response.getWriter();
			    response.setContentType("text/xml;charset=utf-8");
		    	
			    out.println(resultString);
			    out.close();			
			}else{

				result = 2;
				resultString = "<response><result>"+result+"</result></response>";
			    PrintWriter out = response.getWriter();
			    response.setContentType("text/xml;charset=utf-8");
			   
			    out.println(resultString);
			    out.close();
			}
 		}
	}
}
